package Thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class ThreadDemo22 {
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        //创建个任务,需要找个人完成这个任务
        Callable<Integer> callable = new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                int a = 0;
                for (int i = 1; i <=1000 ; i++) {
                    a+=i;
                }
                return a;
            }
        };
        FutureTask<Integer> futureTask = new FutureTask(callable);
        Thread t = new Thread(futureTask);
        t.start();
        t.join();
        System.out.println(futureTask.get());

    }
}
